package com.endurance.controller;

import com.endurance.feign.ProductClients;
import com.endurance.po.Product;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @Author: sunlin
 * @Date: 2024-04-17 13:52
 * @Version: 1.0
 * @Description: OperFeign客户端的调用
 */

@RestController
@RequestMapping("/openFeign")
public class OperFeignController {
    // http://localhost:10003/openFeign/method1/%E5%B0%8F%E7%90%B3
    // http://localhost:10003/openFeign/method2
    // http://localhost:10003/openFeign/method3/%E5%B0%8F%E7%90%B3
    // http://localhost:10003/openFeign/method4


    @Autowired
    private ProductClients productClients;

    @GetMapping
    public HashMap openFeign() {
        HashMap all = productClients.findAll();
        System.out.println(all);
        return all;
    }

    @GetMapping("/method1/{name}")
    public HashMap method1(@PathVariable("name") String name) throws InterruptedException {
        HashMap all = productClients.method1(name);
        System.out.println(all);
        return all;
    }

    @GetMapping("/method2")
    public HashMap method2() {
        Product product = new Product("苹果", 4.9);
        HashMap all = productClients.method2(product);
        System.out.println(all);
        return all;
    }

    @GetMapping("/method3/{name}")
    public HashMap method3(@PathVariable("name") String name) {
        HashMap all = productClients.method3(name);
        System.out.println(all);
        return all;
    }

    @GetMapping("/method4")
    public HashMap method4() {
        Product product = new Product("香蕉", 3.9);
        HashMap all = productClients.method4(product);
        System.out.println(all);
        return all;
    }


}
